package com.weidft.dal.warehouse.dao.ibatis;

import java.util.List;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.weidft.dal.warehouse.dao.ISaleDao;
import com.weidft.dal.warehouse.daoobject.SaleAndResultDO;
import com.weidft.dal.warehouse.daoobject.SaleDO;
import com.weidft.dal.warehouse.daoobject.SaleSpecDO;

public class IBatisSaleDao extends SqlMapClientDaoSupport implements ISaleDao
{

    
    public Integer insertSale(SaleDO saledo)
    {
        int id =  (Integer) getSqlMapClientTemplate().insert(
                "WAREHOUSE_SALE.insert_sale", saledo);
        return id;
    }
    
    public Integer insertSaleSpec(SaleSpecDO saledo)
    {
        int id =  (Integer) getSqlMapClientTemplate().insert(
                "WAREHOUSE_SALESPEC.insert_salespec", saledo);
        return id;
    }

    
    public int getMaxid()
    {
        Object o = getSqlMapClientTemplate().queryForObject(
        "WAREHOUSE_SALE.count_sale_maxid");
        if (o == null)
        {
            return 0;
        }
        else
        {
            return (Integer)o;
        }
    }
 
    
    public Integer countsale(SaleDO saleDO)
    {
        return (Integer) getSqlMapClientTemplate().queryForObject("WAREHOUSE_SALE.count_sale", saleDO);
    }

    
    @SuppressWarnings("unchecked")
    public List<SaleDO> listSale(SaleDO saleDO)
    {
        return getSqlMapClientTemplate().queryForList(
                "WAREHOUSE_SALE.list_sale", saleDO);
    }

    
    public SaleDO getSaleById(int id)
    {
        return (SaleDO) getSqlMapClientTemplate().queryForObject(
                "WAREHOUSE_SALE.get_by_id", id);
    }

    
    @SuppressWarnings("unchecked")
    public List<SaleSpecDO> getSaleSpecsBySaleId(int id)
    {
        return getSqlMapClientTemplate().queryForList(
                "WAREHOUSE_SALESPEC.list_salespec_by_saleid", id);
    }

    @SuppressWarnings("unchecked")
    public List<SaleAndResultDO> listSaleAndResult(SaleDO query)
    {
        return getSqlMapClientTemplate().queryForList(
                "WAREHOUSE_SALESPEC.list_saleAndResult",query);
    }

    
    public void updateSale(SaleDO saleDO)
    {
        getSqlMapClientTemplate().update(
                "WAREHOUSE_SALE.update_sale", saleDO);
    }
    
    public void deleteSaleById(int id)
    {
    	getSqlMapClientTemplate().update("WAREHOUSE_SALE.delete_sale", id);
    }

    
    public void updateSaleSpec(SaleSpecDO saleSpecDO)
    {
        getSqlMapClientTemplate().update(
                "WAREHOUSE_SALESPEC.update_salespec", saleSpecDO);
    }

    
    public void deleteSaleSpec(int id)
    {
        getSqlMapClientTemplate().delete("WAREHOUSE_SALESPEC.delete_salespec", id);
    }
    
    
    

}
